import 'dart:convert';

import 'package:date_format/date_format.dart';
import 'package:dio/dio.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'package:flutter_hotwork/bean/lishishujuquxianbean.dart';
import 'package:flutter_hotwork/bean/maxandminbean.dart';
import 'package:flutter_hotwork/bean/qitagaikuangbean.dart';
import 'package:flutter_hotwork/fuheyuce/TextWeidge.dart';
import 'package:flutter_hotwork/home/RoadChoice.dart';
import 'package:flutter_hotwork/homepage/BaseTitleBar.dart';
import 'package:flutter_hotwork/homepage/BaseViewBar.dart';
import 'package:charts_flutter/flutter.dart' as charts;
import 'package:flutter_hotwork/utils/DioUtils.dart';
import 'package:fluttertoast/fluttertoast.dart';
import '../HomePage.dart';
import '../LoadingDialog.dart';
import '../Toast.dart';
import 'HistoryLineByTwoDate.dart';

class LineChartSample2test extends StatefulWidget {
  @override
  ChartPageState createState() => ChartPageState();
}


class SeriesDatas {
  final int time;
  final double data;

  SeriesDatas(this.time, this.data);
}
class ChartPageState extends State<LineChartSample2test> {

  Map selectArea;
  bool hasdata=false;
  lishishujuquxianbean quxianbean;
  maxandminbean mamibean;
  qitagaikuangbean gaikuang;
  TabController _tabController;
  GlobalKey<TextWidgetState> textKey = GlobalKey();  //设置key,绑定待刷新控件.
  var sel = 0;
  String _year;
  double _sales;
//  点击柱状图触发的函数
  _onSelectionChanged(charts.SelectionModel model) {
    final selectedDatum = model.selectedDatum;
    print(selectedDatum.first.datum.time);
    // setState(() {
    //改变两个显示的数值
    _year = quxianbean.result[0].lists[selectedDatum.first.datum.time].createTime;
    _sales = selectedDatum.first.datum.data;
    textKey.currentState.onPressed("时间："+_year);
    // });
  }

  @override
  Widget build(BuildContext context) {
    return
      new MaterialApp(
        home:
        Scaffold(
          appBar:
          new BaseViewBar(
              childView: new BaseTitleBar(
                "历史曲线",
                leftIcon: 'images/fanhui.png',
                rightIcon:  "",
                rightClick: () {
                  print("点击了右边干嘛啊。。。哦");
                },
                leftClick: () {
                  Navigator.of(context).pop();
                  print("点击了左边干嘛啊。。。哦");
                },
              ),
              preferredSize: Size.fromHeight(50.0)),

          body:
          Card(
              child:
              new CustomScrollView(
                shrinkWrap: true,
                // 内容
                slivers: <Widget>[
                  new SliverPadding(
                    padding: const EdgeInsets.all(0),
                    sliver: new SliverList(
                      delegate: new SliverChildListDelegate(
                        <Widget>[
                          Container(
                            child: Row(
                              children: [
                                Container(
                                  margin:  EdgeInsets.only(left: 0, right: 0, top:5, bottom: 5),
                                  child:
                                  InkWell(
                                    onTap: (){
                                      showModalBottomSheet(context: context,builder: (_)=>Container(
                                        height: 200.0,
                                        child: AreaSelection(
                                          onSelect: handleSelect,
                                          initProviceIndex: selectArea == null ? 0 : selectArea['proviceIndex'],
                                          initCityIndex: selectArea == null ? 0 : selectArea['cityIndex'],
                                        ),
                                      ));
                                    },
                                    child:
                                    Container(
                                        height: 20,
                                        margin: EdgeInsets.only(left: 10, right: 0, top:0, bottom: 0),
                                        padding:  EdgeInsets.only(left: 2, right: 0, top:0, bottom: 0),
                                        decoration: BoxDecoration(
                                          border: new Border.all(color: Colors.blue, width: 0.5), // 边色与边宽度
                                          color: Colors.white, // 底色
                                          //        borderRadius: new BorderRadius.circular((20.0)), // 圆角度
                                        ),
                                        child:
                                        Row(
                                          children: [
                                            Container(
                                              width:100,
                                              child:
                                            Text(selectArea != null ? selectArea['address'] : "请选择用户"  ,
                                              style: TextStyle(color: Colors.black,fontSize: 10),
                                              overflow: TextOverflow.ellipsis,
                                            ) ,
                                            ),

                                            Container(width: 5,),
                                            Image.asset(
                                              'images/jiantou.png',
                                              width: 14.0,
                                              height: 20.0,
                                            ),
                                          ],
                                        )
                                    ),
                                  ),
                                ),

                                FlatButton(
                                  onPressed: () {
                                    DatePicker.showDatePicker(context,
                                        // 是否展示顶部操作按钮
                                        showTitleActions: true,
                                        // 最小时间
                                        minTime: DateTime(2018, 3, 5),
                                        // 最大时间
                                        maxTime: DateTime(2099, 6, 7),
                                        // change事件
                                        onChanged: (date) {

                                          print('change $date');
                                        },
                                        // 确定事件
                                        onConfirm: (date) {
                                          time = formatDate(date,[yyyy,'-',mm,"-",dd]);
                                          time2 = formatDate(date,[yyyy,'-',mm]);
                                          time3 = formatDate(date,[yyyy]);
                                          getribaobiaoList();
                                          // setState(() {
                                          //
                                          // });
                                          print('confirm $time');
                                        },
                                        // 当前时间
                                        currentTime: DateTime.now(),
                                        // 语言
                                        locale: LocaleType.zh);
                                  },
                                  child:
                                  Container(
                                      width: 100,
                                      height: 20,
                                      margin: EdgeInsets.only(left: 10, right: 0, top:0, bottom: 0),
                                      padding:  EdgeInsets.only(left: 10, right: 0, top:0, bottom: 0),
                                      decoration: BoxDecoration(
                                        border: new Border.all(color: Colors.blue, width: 0.5), // 边色与边宽度
                                        color: Colors.white, // 底色
                                        //        borderRadius: new BorderRadius.circular((20.0)), // 圆角度
                                      ),
                                      child:
                                      Row(
                                        children: [
                                          Image.asset(
                                            'images/rili.png',
                                            width: 14.0,
                                            height: 20.0,
                                          ),
                                          Container(width: 5,),
                                          Text(
                                            '$time',
                                            style: TextStyle(color: Colors.black,fontSize: 10),
                                          )

                                        ],
                                      )
                                  ),
                                ),

                                InkWell(
                                  onTap: (){
                                    getribaobiaoList();
                                    // getmaxandminList();
                                  },
                                  child:
                                  Container(
                                      width: 50,
                                      height: 20,
                                      margin: EdgeInsets.only(left: 10, right: 0, top:0, bottom: 0),
                                      padding:  EdgeInsets.only(left: 2, right: 2, top:0, bottom: 0),
                                      decoration: BoxDecoration(
                                        // border: new Border.all(color: Colors.blue, width: 0.5), // 边色与边宽度
                                        color: Colors.blue, // 底色
                                        borderRadius: new BorderRadius.circular((5.0)), // 圆角度
                                      ),
                                      child:
                                      Row(
                                        mainAxisAlignment:MainAxisAlignment.center,
                                        children: [
                                          Text("查询",
                                            style: TextStyle(color: Colors.white,fontSize: 10),
                                          )

                                        ],
                                      )
                                  ),
                                ),
                              ],
                            ),
                          ),
                          Row(
                            children: <Widget>[
                              InkWell(
                                onTap: (){
                                  Navigator.push(context, MaterialPageRoute(builder: (context) {
                                    return new LineChartSample2testAc();
                                  }));
                                },
                                child:
                                Container(
                                    width: 80,
                                    height: 20,
                                    margin: EdgeInsets.only(left: 10, right: 0, top:0, bottom: 0),
                                    padding:  EdgeInsets.only(left: 2, right: 2, top:0, bottom: 0),
                                    decoration: BoxDecoration(
                                      // border: new Border.all(color: Colors.blue, width: 0.5), // 边色与边宽度
                                      color: Colors.blue, // 底色
                                      borderRadius: new BorderRadius.circular((5.0)), // 圆角度
                                    ),
                                    child:
                                    Row(
                                      mainAxisAlignment:MainAxisAlignment.center,
                                      children: [
                                        Text("按时间段查询",
                                          style: TextStyle(color: Colors.white,fontSize: 10),
                                        )

                                      ],
                                    )
                                ),
                              ),
                              Flexible(fit: FlexFit.tight, child: SizedBox()),
                              Text("日:"),
                              Radio(
                                value: 0,
                                groupValue: this.sel,
                                onChanged: (value) {
                                  this.sel = value;
                                  getribaobiaoList();
                                },
                              ),
                              Text("月:"),
                              Container(
                                child:
                                Radio(
                                  value: 1,
                                  groupValue: this.sel,
                                  onChanged: (value) {
                                    this.sel = value;
                                    getribaobiaoList();
                                  },
                                ),
                              ),

                              Text("年:"),
                              Radio(
                                value: 2,
                                groupValue: this.sel,
                                onChanged: (value) {
                                  this.sel = value;
                                  getribaobiaoList();
                                },
                              )
                            ],
                          ),
                          hasdata?
                          Column(
                            children: [
                              _chartWidget(),
                              mamibean!=null?
                              DefaultTabController(
                                length: 6,
                                child:
                                Column(
                                  children:[
                                    TabBar(
                                      labelColor: Colors.blue,
                                      unselectedLabelColor: Colors.black,
                                      indicatorColor: Colors.blue,
                                      tabs: <Widget>[
                                        Text("工作温度",style: TextStyle(fontSize: 10),),
                                        Text("工作压力",style: TextStyle(fontSize: 10),),
                                        Text("累计流量",style: TextStyle(fontSize: 10),),
                                        Text("阀后温度",style: TextStyle(fontSize: 10),),
                                        Text("瞬时流量",style: TextStyle(fontSize: 10),),
                                        Text("其他概况",style: TextStyle(fontSize: 10),),
                                      ],
                                      controller: _tabController,  // 记得要带上tabController
                                    ),
                                    Container(
                                      height: 247,
                                      child:
                                      TabBarView(
                                        controller: _tabController,
                                        children: <Widget>[
                                          Center(
                                            child:
                                            Container(
                                              padding: EdgeInsets.only(left:10,top: 10),
                                              child:
                                              Column(
                                                children: [
                                                  Row(
                                                      children:[
                                                        Text("用户名称:   ",style: TextStyle(fontSize: 14),),
                                                        Text(selectArea['address'],style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("平均值:   ",style: TextStyle(fontSize: 14),),
                                                        Text(mamibean.result[0].queryAvg.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("最大值:   ",style: TextStyle(fontSize: 14),),
                                                        Text(mamibean.result[0].queryMax.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("发生时间:   ",style: TextStyle(fontSize: 14),),
                                                        Text(mamibean.result[0].queryMaxDate.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("最小值:   ",style: TextStyle(fontSize: 14),),
                                                        Text(mamibean.result[0].queryMin.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("发生时间:   ",style: TextStyle(fontSize: 14),),
                                                        Text(mamibean.result[0].queryMinDate.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                ],

                                              ),

                                            ),

                                          ),
                                          Center(
                                            child:
                                            Container(
                                              padding: EdgeInsets.only(left:10,top: 10),
                                              child:
                                              Column(
                                                children: [
                                                  Row(
                                                      children:[
                                                        Text("用户名称:   ",style: TextStyle(fontSize: 14),),
                                                        Text(selectArea['address'],style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("平均值:   ",style: TextStyle(fontSize: 14),),
                                                        Text(mamibean.result[2].queryAvg.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("最大值:   ",style: TextStyle(fontSize: 14),),
                                                        Text(mamibean.result[2].queryMax.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("发生时间:   ",style: TextStyle(fontSize: 14),),
                                                        Text(mamibean.result[2].queryMaxDate.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("最小值:   ",style: TextStyle(fontSize: 14),),
                                                        Text(mamibean.result[2].queryMin.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("发生时间:   ",style: TextStyle(fontSize: 14),),
                                                        Text(mamibean.result[2].queryMinDate.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                ],

                                              ),

                                            ),

                                          ),
                                          Center(
                                            child:
                                            Container(
                                              padding: EdgeInsets.only(left:10,top: 10),
                                              child:
                                              Column(
                                                children: [
                                                  Row(
                                                      children:[
                                                        Text("用户名称:   ",style: TextStyle(fontSize: 14),),
                                                        Text(selectArea['address'],style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("平均值:   ",style: TextStyle(fontSize: 14),),
                                                        Text(mamibean.result[4].queryAvg.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("最大值:   ",style: TextStyle(fontSize: 14),),
                                                        Text(mamibean.result[4].queryMax.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("发生时间:   ",style: TextStyle(fontSize: 14),),
                                                        Text(mamibean.result[4].queryMaxDate.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("最小值:   ",style: TextStyle(fontSize: 14),),
                                                        Text(mamibean.result[4].queryMin.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("发生时间:   ",style: TextStyle(fontSize: 14),),
                                                        Text(mamibean.result[4].queryMinDate.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                ],

                                              ),

                                            ),

                                          ),
                                          Center(
                                            child:
                                            Container(
                                              padding: EdgeInsets.only(left:10,top: 10),
                                              child:
                                              Column(
                                                children: [
                                                  Row(
                                                      children:[
                                                        Text("用户名称:   ",style: TextStyle(fontSize: 14),),
                                                        Text(selectArea['address'],style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("平均值:   ",style: TextStyle(fontSize: 14),),
                                                        Text(mamibean.result[1].queryAvg.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("最大值:   ",style: TextStyle(fontSize: 14),),
                                                        Text(mamibean.result[1].queryMax.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("发生时间:   ",style: TextStyle(fontSize: 14),),
                                                        Text(mamibean.result[1].queryMaxDate.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("最小值:   ",style: TextStyle(fontSize: 14),),
                                                        Text(mamibean.result[1].queryMin.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("发生时间:   ",style: TextStyle(fontSize: 14),),
                                                        Text(mamibean.result[1].queryMinDate.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                ],

                                              ),

                                            ),

                                          ),
                                          Center(
                                            child:
                                            Container(
                                              padding: EdgeInsets.only(left:10,top: 10),
                                              child:
                                              Column(
                                                children: [
                                                  Row(
                                                      children:[
                                                        Text("用户名称:   ",style: TextStyle(fontSize: 14),),
                                                        Text(selectArea['address'],style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("平均值:   ",style: TextStyle(fontSize: 14),),
                                                        Text(mamibean.result[3].queryAvg.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("最大值:   ",style: TextStyle(fontSize: 14),),
                                                        Text(mamibean.result[3].queryMax.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("发生时间:   ",style: TextStyle(fontSize: 14),),
                                                        Text(mamibean.result[3].queryMaxDate.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("最小值:   ",style: TextStyle(fontSize: 14),),
                                                        Text(mamibean.result[3].queryMin.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("发生时间:   ",style: TextStyle(fontSize: 14),),
                                                        Text(mamibean.result[3].queryMinDate.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                ],

                                              ),

                                            ),

                                          ),
                                          Center(
                                            child:
                                            Container(
                                              padding: EdgeInsets.only(left:10,top: 10),
                                              child:
                                              Column(
                                                children: [
                                                  Row(
                                                      children:[
                                                        Text("用户名称:   ",style: TextStyle(fontSize: 14),),
                                                        Text(selectArea['address'],style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("余量:   ",style: TextStyle(fontSize: 14),),
                                                        Text(gaikuang.result[0].steam.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("余额:   ",style: TextStyle(fontSize: 14),),
                                                        Text(gaikuang.result[0].balance.toString(),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("介质状态:   ",style: TextStyle(fontSize: 14),),
                                                        Text(getjiezhi(gaikuang.result[0].mediumState),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("累计方式:   ",style: TextStyle(fontSize: 14),),
                                                        Text(getleiji(gaikuang.result[0].flowType),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                  Row(
                                                      children:[
                                                        Text("阀门状态:   ",style: TextStyle(fontSize: 14),),
                                                        Text(famen(gaikuang.result[0].valveStatus),style: TextStyle(fontSize: 12),),
                                                      ]
                                                  ),
                                                ],

                                              ),

                                            ),

                                          ),
                                        ],
                                      ),
                                    ),

                                  ],
                                ),
                              ):Container(),
                            ],
                          )


                              :
                          Container(),
                        ],
                      ),
                    ),
                  ),
                ],
              )

          ),
        ),
      );
  }


  String getjiezhi(int tag){
    String jiezhi;
    if(tag == 0){
      jiezhi ="过热";
    }else
    if(tag == 1){
      jiezhi ="饱和";
    }else
    if(tag == 2){
      jiezhi ="水";
    }else
    {
      jiezhi ="***";
    }
    return jiezhi;
  }

  String getleiji(int tag){
    String jiezhi;
    if(tag == 0){
      jiezhi ="微小流量";
    }else
    if(tag == 1){
      jiezhi ="小流量";
    }else
    if(tag == 2){
      jiezhi ="正常";
    }else
    if(tag == 3){
      jiezhi ="超量程";
    }
    else
    {
      jiezhi ="***";
    }
    return jiezhi;
  }

  String famen(int tag){
    String jiezhi;
    if(tag == 0){
      jiezhi ="开";
    }else
    if(tag == 1){
      jiezhi ="关";
    }else
    {
      jiezhi ="***";
    }
    return jiezhi;
  }
  ///接收选择的结果
  void handleSelect (Map targetArea) {
    setState(() {
      selectArea = targetArea;
      getribaobiaoList();
      // initData(selectArea['proviceIndex'],selectArea['cityIndex']);
    });
  }
  @override
  void initState() {
    super.initState();
    DioUtils.createInstance();
  }

  @override
  void dispose() {
//    _amapLocation.stopLocate();
    super.dispose();
    hasdata = false;
  }
  var time = formatDate(new DateTime.now(),[yyyy,'-',mm,"-",dd]);
  var time2 = formatDate(new DateTime.now(),[yyyy,'-',mm]);
  var time3 = formatDate(new DateTime.now(),[yyyy]);
  void getribaobiaoList() async {
    showDialog(
        context: context,
        builder: (context) {
          return new LoadingDialog();
        });
    // Navigator.pop(context);
    try {

      var reqeuest =Map<Object,Object>();
      if(sel==0){
        reqeuest["dateEnum"] = "DAY";
      }else if(sel==1){
        reqeuest["dateEnum"] = "MONTH";
      }else{
        reqeuest["dateEnum"] = "YEAR";
      }

      reqeuest["ids"] = [selectArea['id']];
      reqeuest["indexTypeEmun"] = "ALL";
      if(sel==0){
        reqeuest["dateEnum"] = "DAY";
        reqeuest["queryDate"] = time;
      }else if(sel==1){
        reqeuest["dateEnum"] = "MONTH";
        reqeuest["queryDate"] = time2;
      }else{
        reqeuest["dateEnum"] = "YEAR";
        reqeuest["queryDate"] = time3;
      }
      reqeuest["whetherEnum"] = "YES";
      Response response;
      response = await DioUtils.dio.post(DioUtils.API_PREFIX+"/RegularData/listHotUserCurveAnalysis", data: json.encode(reqeuest));
      Map respMap = json.decode(response.data);
      quxianbean  = lishishujuquxianbean.fromJson(respMap);
      Navigator.pop(context);
      if (quxianbean.code == 0) {
        if(null!=quxianbean.result&&quxianbean.result.length>0) {
          getmaxandminList();
          setState(() {
            hasdata = true;
          });
        }else {
          LocalToast.toast(context,msg: "暂无数据");
        }
      } else {
        LocalToast.toast(context,msg: quxianbean.message);
      }
    } catch (e) {
      Navigator.pop(context);
      LocalToast.toast(context,msg: "暂无数据");
    }
  }

  void listOtherSituationVo() async {
    try {

      var reqeuest =Map<Object,Object>();
      reqeuest["ids"] = [selectArea['id']];
      Response response;
      response = await DioUtils.dio.post(DioUtils.API_PREFIX+"/RegularData/listOtherSituationVo", data: [selectArea['id']]);
      Map respMap = json.decode(response.data);
      gaikuang  = qitagaikuangbean.fromJson(respMap);
      if (mamibean.code == 0) {

        hasdata=true;
        setState(() {

        });
      } else {
        LocalToast.toast(context,msg: mamibean.message);
      }
    } catch (e) {
      LocalToast.toast(context,msg: "暂无数据");
    }
  }
  void getmaxandminList() async {
    try {

      var reqeuest =Map<Object,Object>();
      if(sel==0){
        reqeuest["dateEnum"] = "DAY";
        reqeuest["queryDate"] = time;
      }else if(sel==1){
        reqeuest["dateEnum"] = "MONTH";
        reqeuest["queryDate"] = time2;
      }else{
        reqeuest["dateEnum"] = "YEAR";
        reqeuest["queryDate"] = time3;
      }
      reqeuest["ids"] = [selectArea['id']];
      reqeuest["indexTypeEmun"] = "ALL";
      reqeuest["whetherEnum"] = "YES";
      Response response;
      response = await DioUtils.dio.post(DioUtils.API_PREFIX+"/RegularData/listIndexVo", data: json.encode(reqeuest));
      Map respMap = json.decode(response.data);
      mamibean  = maxandminbean.fromJson(respMap);
      if (mamibean.code == 0) {
        listOtherSituationVo();
        // hasdata=true;
        // setState(() {
        //
        // });
      } else {
        LocalToast.toast(context,msg: mamibean.message);
      }
    } catch (e) {
      LocalToast.toast(context,msg: "暂无数据");
    }
  }

  List<SeriesDatas> data1(){
    List<SeriesDatas> listdata = new List<SeriesDatas>();
    for(int i =0;i<quxianbean.result[0].lists.length;i++){//
      SeriesDatas data=new SeriesDatas(i, quxianbean.result[0].lists[i].jobTemperature);
      // SeriesDatas data=new SeriesDatas("", quxianbean.result[0].lists[i].jobTemperature);
      // SeriesDatas data=new SeriesDatas(quxianbean.result[0].lists[i].createTime, quxianbean.result[0].lists[i].jobTemperature);
      listdata.add(data);
    }
    return listdata;
  }

  List<SeriesDatas> data2(){
    List<SeriesDatas> listdata = new List<SeriesDatas>();
    for(int i =0;i<quxianbean.result[0].lists.length;i++){
      SeriesDatas data=new SeriesDatas(i, quxianbean.result[0].lists[i].jobStress);
      // SeriesDatas data=new SeriesDatas("", quxianbean.result[0].lists[i].jobStress);
      // SeriesDatas data=new SeriesDatas(quxianbean.result[0].lists[i].createTime, quxianbean.result[0].lists[i].jobStress);
      listdata.add(data);
    }
    return listdata;
  }

  List<SeriesDatas> data3(){
    List<SeriesDatas> listdata = new List<SeriesDatas>();
    for(int i =0;i<quxianbean.result[0].lists.length;i++){
      SeriesDatas data=new SeriesDatas(i, quxianbean.result[0].lists[i].totalFlow);
      // SeriesDatas data=new SeriesDatas("", quxianbean.result[0].lists[i].totalFlow);
      // SeriesDatas data=new SeriesDatas(quxianbean.result[0].lists[i].createTime, quxianbean.result[0].lists[i].totalFlow);
      listdata.add(data);
    }
    return listdata;
  }

  List<SeriesDatas> data4(){
    List<SeriesDatas> listdata = new List<SeriesDatas>();
    for(int i =0;i<quxianbean.result[0].lists.length;i++){
      SeriesDatas data=new SeriesDatas(i, quxianbean.result[0].lists[i].afterValveTemperature);
      // SeriesDatas data=new SeriesDatas("", quxianbean.result[0].lists[i].afterValveTemperature);
      // SeriesDatas data=new SeriesDatas(quxianbean.result[0].lists[i].createTime, quxianbean.result[0].lists[i].afterValveTemperature);
      listdata.add(data);
    }
    return listdata;
  }

  List<SeriesDatas> data5(){
    List<SeriesDatas> listdata = new List<SeriesDatas>();
    for(int i =0;i<quxianbean.result[0].lists.length;i++){
      SeriesDatas data=new SeriesDatas(i, quxianbean.result[0].lists[i].instantFlow);
      // SeriesDatas data=new SeriesDatas("", quxianbean.result[0].lists[i].instantFlow);
      // SeriesDatas data=new SeriesDatas(quxianbean.result[0].lists[i].createTime, quxianbean.result[0].lists[i].instantFlow);
      listdata.add(data);
    }
    return listdata;
  }

  // 折线图
  Widget _chartWidget() {
    List<charts.Series<SeriesDatas, int>> seriesList = [
      new charts.Series<SeriesDatas, int>(
        id: '工作温度',
        colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault,
        domainFn: (SeriesDatas sales, _) => sales.time,
        measureFn: (SeriesDatas sales, _) => sales.data,
        data: data1(),
      ),
      new charts.Series<SeriesDatas, int>(
        id: '工作压力',
        colorFn: (_, __) => charts.MaterialPalette.yellow.shadeDefault,
        domainFn: (SeriesDatas sales, _) => sales.time,
        measureFn: (SeriesDatas sales, _) => sales.data,
        data: data2(),
      ),
      new charts.Series<SeriesDatas, int>(
        id: '累计流量',
        colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
        domainFn: (SeriesDatas sales, _) => sales.time,
        measureFn: (SeriesDatas sales, _) => sales.data,
        data: data3(),
      ),
      new charts.Series<SeriesDatas, int>(
        id: '阀后温度',
        colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault,
        domainFn: (SeriesDatas sales, _) => sales.time,
        measureFn: (SeriesDatas sales, _) => sales.data,
        data: data4(),
      ),
      new charts.Series<SeriesDatas, int>(
        id: '瞬时流量',
        colorFn: (_, __) => charts.MaterialPalette.purple.shadeDefault,
        domainFn: (SeriesDatas sales, _) => sales.time,
        measureFn: (SeriesDatas sales, _) => sales.data,
        data: data5(),
      )
    ];

    var chart = new charts.LineChart(
      seriesList,
      animate: true,
      defaultRenderer: charts.LineRendererConfig( // 折线图绘制的配置
        includeArea: false,
        includePoints: false,
        includeLine: true,
        stacked: false,
      ),
      selectionModels: [
        charts.SelectionModelConfig(
          type: charts.SelectionModelType.info,
          changedListener: _onSelectionChanged,
        )
      ],
      domainAxis: charts.NumericAxisSpec( // 主轴的配置
        // tickFormatterSpec: DomainFormatterSpec(widget.dateRange), // tick 值的格式化，这里把 num 转换成 String
        renderSpec: charts.SmallTickRendererSpec( // 主轴绘制的配置
          tickLengthPx: 0, // 刻度标识突出的长度
          labelOffsetFromAxisPx: 12, // 刻度文字距离轴线的位移
          labelStyle: charts.TextStyleSpec( // 刻度文字的样式
            fontSize: 0,
          ),
          lineStyle: charts.LineStyleSpec(
            thickness:1,
          ),
          axisLineStyle: charts.LineStyleSpec(
            // 轴线的样式
          ),
        ),
        tickProviderSpec: charts.BasicNumericTickProviderSpec( // 轴线刻度配置
          dataIsInWholeNumbers: false,
          desiredTickCount: 5, // 期望显示几个刻度
        ),
      ),
      primaryMeasureAxis: charts.NumericAxisSpec( // 交叉轴的配置，参数参考主轴配置
        showAxisLine: false, // 显示轴线
        // tickFormatterSpec: MeasureFormatterSpec(),
        tickProviderSpec: charts.BasicNumericTickProviderSpec(
          dataIsInWholeNumbers: false,
          desiredTickCount: 4,
        ),
        renderSpec: charts.GridlineRendererSpec( // 交叉轴刻度水平线
          tickLengthPx: 0,
          labelOffsetFromAxisPx: 12,
          labelStyle: charts.TextStyleSpec(
            // color: ChartUtil.getChartColor(HColors.lightGrey),
            fontSize:10,
          ),
          lineStyle: charts.LineStyleSpec(
            // color: ChartUtil.getChartColor(ChartUtil.lightBlue),
          ),
          axisLineStyle: charts.LineStyleSpec(
            // color: ChartUtil.getChartColor(ChartUtil.lightBlue),
          ),
        ),
      ),
      behaviors: [
        new charts.SeriesLegend(
          // 图例位置 在左侧start 和右侧end
            position: charts.BehaviorPosition.bottom,
            // 图例条目  [horizo​​ntalFirst]设置为false，图例条目将首先作为新行而不是新列增长
            horizontalFirst: false,
            // 每个图例条目周围的填充Padding
            cellPadding: new EdgeInsets.only(right: 4.0, bottom: 4.0),
            // 显示度量
            showMeasures: true,
            // 度量格式
            measureFormatter: (num value) {
              return value == null ? '-' : '${value}';
            }
          // ,
        ),

      ],
    );
    return new Card(
      child: Container(
        height: 470,
        // padding: new EdgeInsets.fromLTRB(16, 10, 16, 20),
        // margin: new EdgeInsets.only(bottom: 20),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            new Center(
              child: new Text(
                '热用户曲线分析',
                style: TextStyle(
                  color: Color.fromRGBO(0, 0, 0, 1.0), //opacity：不透明度
                  fontFamily: 'PingFangBold',
                  fontSize: 15.0,
                ),
              ),
            ),
            new Padding(
              padding: new EdgeInsets.all(10.0),
              child: new SizedBox(
                height: 400.0,
                child: chart,
              ),

            )
            ,new Center(
              child: TextWidget(textKey),
            ),
          ],
        ),
      ),
    );
  }

  String getTime(num sell){
    double sellmoney = sell;
    for(int i = 0;i<quxianbean.result[0].lists.length;i++){
      if(sellmoney==quxianbean.result[0].lists[i].jobTemperature){
        return quxianbean.result[0].lists[i].createTime;
      }
      if(sellmoney==quxianbean.result[0].lists[i].jobStress){
        return quxianbean.result[0].lists[i].createTime;
      }
      if(sellmoney==quxianbean.result[0].lists[i].totalFlow){
        return quxianbean.result[0].lists[i].createTime;
      }
      if(sellmoney==quxianbean.result[0].lists[i].afterValveTemperature){
        return quxianbean.result[0].lists[i].createTime;
      }
      if(sellmoney==quxianbean.result[0].lists[i].instantFlow){
        return quxianbean.result[0].lists[i].createTime;
      }
    }
  }
}